/* eslint-disable import/no-cycle */
import { post, get } from '@/utils/request';

/**
 * 获取七牛云上传token
 * @param {Object} param0
 * @param {Boolean} useCache 是否使用token的缓存
 * @param {String} bucket 七牛云存储区域 ugc-pro 生产 | ugc-dev 测试
 */
// eslint-disable-next-line import/prefer-default-export
export const getQiniuToken = ({ useCache = false, bucket = '' } = { useCache: false, bucket: '' }) => {
  if (!bucket) {
    // eslint-disable-next-line no-param-reassign
    bucket = process.env.NODE_ENV === 'production' ? 'ugc-pro' : 'ugc-dev';
  }
  return post('/demeter/api/file/upload/token', { useCache, bucket });
};

// 获取用户登录信息
export const postAuthUserLogin = (data) => post('/users/api/comm/wechat/ep/jscode2session', data);

// 登录绑定
export const postOpenIdBind = (data) => post('/users/api/h5/user/openid-bind', data);

// 获取获取图片信息
export const getQiniuImgInfo = (params) =>
  post('/demeter/api/file/image/info', params, {
    contentType: 'json',
  });

// 逆地址解析
export function getAddressByLocation(location) {
  return get('https://api.map.baidu.com/reverse_geocoding/v3/', {
    location,
    coordtype: 'bd09ll',
    output: 'json',
    extensions_poi: 0,
  });
}

// 坐标转换 默认gcj02转bd09ll坐标
export function getLocationByOtherLocation(coords, from = 3, to = 5) {
  return get('https://api.map.baidu.com/geoconv/v1/', {
    coords,
    from,
    to,
    output: 'json',
  });
}

/**
 * 检查用户是否绑定过微信
 */
export const getUerBindResult = (data) => post('/users/api/h5/user/wechat/bind/check', data);
